const { HttpLink } = require('apollo-link-http')
const fetch = require('node-fetch')
const {
  introspectSchema,
  makeRemoteExecutableSchema
} = require('graphql-tools')

module.exports = async uri => {
  const link = new HttpLink({ uri, fetch })
  const schema = await introspectSchema(link)

  const executableSchema = makeRemoteExecutableSchema({
    schema,
    link
  })

  return executableSchema
}
